<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<?php 
	$ci = &get_instance();
	$escort_id = intval($this->input->get('escort_id',TRUE));
	$ESCORT = $ci->escort_entity->init('id',$escort_id);
	$LOCKED = $ci->locked_escort_entity->init('escort_id', $ESCORT->getId());
	
	$paymentSelectedArray = $ESCORT->getPaymentMethodIds() ? explode(',',$ESCORT->getPaymentMethodIds()):array();
	$extraSelectedArray = $ESCORT->getExtrasIds() ? explode(',',$ESCORT->getExtrasIds()):array();
	$currentPricingTimeArray = $ESCORT->getPricingTimeIdArray($ESCORT->getId());
?>

<form action="<?php echo site_url('agent/escort/submit_rates');?>" name="submit_rates" id="submit_rates" method="post" enctype="multipart/form-data" >
	<input type="hidden" name="escort_id" value="<?php echo $escort_id;?>" />
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('rates_payment');?></span>
			<div class="help-text" title="<?php echo language_translate('rates_payment_hint');?>"></div>	
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<?php echo multi_checkbox('rates_payment[]', getPaymentTypesData_ioc(), $paymentSelectedArray );?>
			</div>
			<div class="input-box">
				<input type="checkbox" onoff="1" value="1" name="rates_public_payment" class="custom" 
					<?php echo $ESCORT->getPublicPaymentMethod() == 1 ? "checked='checked'":''; ?> />
			</div>
			
			<?php if($LOCKED->getLockedPaymentMethod() == 1):?>
				<div class="locked"></div>
			<?php endif;?>
			
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('rates_pricing');?></span>
			<div class="help-text" title="<?php echo language_translate('rates_pricing_hint');?>"></div>	
		</div>
		<div class="dashboard-info-right">
			<div style="width:360px;float:left;">
				<?php foreach(getPricingTimeData_ioc() as $key=>$value):?>
					<?php 
						$checked = in_array($key, $currentPricingTimeArray) ? 'checked="checked"':''; 
						$PRICE_OBJ = $ESCORT->getPricingTime($ESCORT->getId(), $key);
						$price = $PRICE_OBJ ? $PRICE_OBJ->price :'';
					?>
					<div class="checkbox-wrapper" style="width:150px;float:left;">
						<input type="checkbox" name="rates_price_time[]" class="custom" value="<?php echo $key?>" <?php echo $checked;?>/>	<label><?php echo $value;?></label>
					</div>
					<div class="select-box" style="width:130px;float:left;margin-right:0px;">
						<input type="text" value="<?php echo $price;?>" name="rates_price_value_<?php echo $key;?>" id="rates_price_value_<?php echo $key;?>" class="text-box" style="text-align:center;" /> &euro;
					</div>
					<div class="input-error rates_price_value hidden" id="rates_price_value_<?php echo $key;?>_err"><?php echo language_translate('rates_price_error');?></div>
					<div class="clear"></div>
				<?php endforeach;?>	
			</div>
			<div class="input-box" style="float:left;">
				<input type="checkbox" onoff="1" value="1" name="rates_public_price" class="custom" 
					<?php echo $ESCORT->getPublicPricingTime() == 1 ? "checked='checked'":''; ?> />
			</div>
			<?php if($LOCKED->getLockedPricingTime() == 1):?>
				<div class="locked"></div>
			<?php endif;?>
			
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('rates_transport');?></span>
			<div class="help-text" title="<?php echo language_translate('rates_transport_hint');?>"></div>	
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<?php echo form_dropdown('rates_transport_id', getTransportData_ioc(), array($ESCORT->getTransportIncludeId()) , 'id="rates_transport_id" class="custom"' );?>
			</div>
			<div class="input-box">
				<input type="checkbox" onoff="1" value="1" name="rates_public_transport" class="custom" 
					<?php echo $ESCORT->getPublicTransportInclude() == 1 ? "checked='checked'":''; ?> />
			</div>
			
			<?php if($LOCKED->getLockedTransport() == 1):?>
				<div class="locked"></div>
			<?php endif;?>
		 </div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('rates_extras');?></span>
			<div class="help-text" title="<?php echo language_translate('rates_extras_hint');?>"></div>	
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<?php echo multi_checkbox('rates_extras[]', getExtrasData_ioc(), $extraSelectedArray );?>
			</div>
			<div class="input-box">
				<input type="checkbox" onoff="1" value="1" name="rates_public_extras" class="custom" 
					<?php echo $ESCORT->getPublicExtras() == 1 ? "checked='checked'":''; ?> />
			</div>
			
			<?php if($LOCKED->getLockedExtras() == 1):?>
				<div class="locked"></div>
			<?php endif;?>
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left"><span>&nbsp;</span></div>
		<div class="dashboard-info-right">
			<div class="link-box">
				<a href="javascript:void(0);" onclick="return open_question_dialog(<?php echo $ESCORT->getId();?>);"><?php echo language_translate('rates_question');?></a>
			</div>
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>

	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left"> 
			<div class="select-box">
				<input type="submit" class="save-button" value="<?php echo language_translate('rates_save');?>" /> 
			</div>
		 </div>
		 <div class="dashboard-info-right">
			<?php echo loader_image("id='rates_loader_image' class='hidden'");?>
		</div>
		<div class="clear"></div>
	</div>	 
	
	<div class="dashboard-info-wrapper">
		<div id="update-message"><?php echo language_translate('update_successfully_message');?></div>
		<div class="clear"></div>
	</div>
	
</form>

<script type="text/javascript">
$(document).ready(function() { 
	var options = { 
		beforeSubmit:  validateB4SubmitRates,  
		success:       processAfterRespondingRates   
	};	
	$('#submit_rates').ajaxForm(options); 
	$('.help-text[title]').qtip({ style: { name: 'dark', tip: true } });
});	
function validateB4SubmitRates(formData, jqForm, options){
	$('#rates_loader_image').show();
	$error = 0;
	$priceTimeArray = getMultiCheckbox('rates_price_time');
	$('.rates_price_value').addClass('hidden');
	for($i =0; $i< $priceTimeArray.length; $i++){
		$price = $('#rates_price_value_'+$priceTimeArray[$i]).attr('value');
		if(! isFloatNumber($price) || $price <= 0){
			$('#rates_price_value_'+$priceTimeArray[$i]+'_err').removeClass('hidden');
			$error++;
		}
	}
	if($error > 0){
		$('#rates_loader_image').hide();
		return false;
	}	
	return true;	
}

function processAfterRespondingRates(responseText, statusText, xhr, $form) {
	$('#rates_loader_image').hide();	
	if(responseText == 'ok'){
		updatedShow();
	}else{
		debug(responseText);
	}
}
</script>